package com.exp.irorichat.service.impl;

import cn.hutool.core.date.DateUtil;
import com.exp.irorichat.entity.User;
import com.exp.irorichat.entity.requst.UserReq;
import com.exp.irorichat.mapper.UserMapper;
import com.exp.irorichat.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author universe7427
 * @since 2024-12-10
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public int addUser(UserReq userReq) {
        User user = new User();
        BeanUtils.copyProperties(userReq,user);
        LocalDateTime localDateTime = DateUtil.toLocalDateTime(new Date());
        user.setCreateTime(localDateTime);
        user.setLastOptTime(localDateTime);
        //TODO 密码加密
        return baseMapper.insert(user);
    }
}
